#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;
using ll = long long;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 2e5 + 10;
const int V = 1e9;

int rt[N],n,m,a[N];
namespace seg {
	const int N = 1e7 + 10;
	int ch[N][2],val[N],ndn;
	void upd(int &x,int y,int pos,int l = 1,int r = V) {
		x = ++ndn; val[x] = val[y] + 1; ch[x][0] = ch[y][0]; ch[x][1] = ch[y][1]; if(l == r) return; int mid = l + r >> 1;
		if(pos <= mid) upd(ch[x][0],ch[y][0],pos,l,mid); else upd(ch[x][1],ch[y][1],pos,mid + 1,r);
	}
	int query(int x,int y,int pos,int l = 1,int r = V) {
		if(l > pos || val[x] - val[y] == 0) return -1; if(l == r) return l; int mid = l + r >> 1;
		int res = query(ch[x][1],ch[y][1],pos,mid + 1,r);
		if(~res) return res;
		return query(ch[x][0],ch[y][0],pos,l,mid);
	}
}

int query(int xl,int xr,int pos) { return seg :: query(rt[xr],rt[xl - 1],pos); }

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    n = in,m = in; rep(i, 1, n) a[i] = in,seg :: upd(rt[i],rt[i - 1],a[i]);
	while(m--) {
		int l1 = in,r1 = in,l2 = in,r2 = in;
		int x = query(l1,r1,V),y = query(l2,r2,V);
		while(true) {
			if(x == -1 || y == -1) { puts("0"); break; }
			else if(x / 2 <= y && y < x) { printf("%d\n",x + y); break; }
			else if(x <= y) { y = query(l2,r2,x - 1); }
			else x = query(l1,r1,2 * y + 1); 
		}
	} return 0;
}
